#ifndef  _CONFIG_H
#define _CONFIG_H
#include <sstream>
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
struct key_value{
    string key;
    string value;
};
class Config{
public:
    static Config *& getConfigObj(){
        if(config_p == nullptr){
            config_p =new Config();
        }
        return config_p;
    }

    static void deleteConfigObj(){
        if(config_p != nullptr){
            delete config_p;
            config_p = nullptr;
        }
    }

    void set_config_path(const string& path){
        fstream fst(path);
        string strs;
        stringstream sst;
        while(getline(fst,strs)){
            sst<<strs;
            string key,value;
            sst>>key>>value;
            sst.str("");
            sst.clear();
            int i;
            for(i=0; i< (int)vconfig.size();i++){
                if(vconfig[i].key==key){
                    vconfig[i].value = value;
                    cout<<value<<endl;
                    break;
                }
            }
            if(i == (int)vconfig.size()){
                vconfig.push_back({key,value});
            }

        }
        fst.close();
    }
    string& getValue(const string& key){
        for(auto & temp: vconfig){
            if(temp.key == key){
                return temp.value;
            }
        }
        static string s;
        return s;
    }
private:
    Config(){}
    Config(const Config & cfg) = delete;
    ~Config(){}
    static Config * config_p;
    vector<key_value> vconfig;
};
#endif
